//获取应用实例
const app = getApp()

Component({
    data: {
      showTextAndTitleWithInput:false,
      boxes:[],
      boxId:"",
      boxName:"",
      reportType:"PDF",
      colors:["#52a4f0","#95cb95","#de7e56"],
      showName:""
    },
    lifetimes: {
      attached: function(options) {

        // 在组件实例进入页面节点树时执行
        wx.request({
          url: app.globalData.url+'/wechat/teacher_report_boxes',
          data: {
            username: app.globalData.localuserinfo.username,
          },
          method: 'POST',
          header: {
            'content-type': 'application/json'
          },
          success: res2 => {
            if(res2.statusCode==200){
              this.setData({boxes:res2.data||[],showName:app.globalData.localuserinfo.showName})
            }
          }

        })
      }
    },

    onLoad: function() {
        var that = this;
        
    },


    
    methods:{
      cellClick:function(e){
        console.log('cellClick')
        const boxId=e.target.id;
        console.log("boxId",boxId)
        this.setData({boxId})
        wx.navigateTo({
          url: "../teacher_m_report_box/teacher_m_report_box?boxId="+boxId,
      });
      },
      showDialog: function(){
        this.setData({showTextAndTitleWithInput:true})
      },
      closeDialog: function(){
        this.setData({showTextAndTitleWithInput:false})
      },
  
      creatReportBox: function(){
        var that = this;
        if (this.data.boxName == "") {
          wx.showToast({
            title: '请输入课程名称',
            icon: 'none',
            duration: 2000
          })
        }else{
          wx.request({
            url: app.globalData.url+'/wechat/creat_report_box',
            data: {
              username: app.globalData.localuserinfo.username,
              name: that.data.boxName,
              token:app.globalData.token
            },
            method: 'POST',
            header: {
              'content-type': 'application/json'
            },
            success: res2 => {
              if(res2.data.name){
                const boxes=that.data.boxes;
               boxes.push(res2.data),
                this.setData({showTextAndTitleWithInput:false,
                  boxes})
              }else{
                wx.showToast({
                  title: '创建失败！',
                  icon: 'none',
                  duration: 2000
                })
              }
            }
          })
        }
      },
      changeBoxName:function(e){
        this.setData({
          boxName: e.detail.value
        })
      }
    },

    cellClick:function(e){
      console.log('cellClick')
      const boxId=e.target.id;
      console.log("boxId",boxId)
      this.setData({boxId})
      wx.navigateTo({
        url: "../teacher_m_report_box/teacher_m_report_box?boxId="+boxId,
    });
    },
    changeBoxName:function(e){
      this.setData({
        boxName: e.detail.value
      })
    }
  
})
